/**
 * 
 */
package dao.hibernate;

import hibernate.Artist;

import java.util.List;

import model.IArtist;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import dao.IArtistDAO;

/**
 * @author isaac
 *
 */
public class ArtistDAO extends BaseHibernateDAO implements IArtistDAO {
	/* (non-Javadoc)
	 * @see dao.IArtistDAO#getArtistByName(java.lang.String)
	 */
	public IArtist getArtistByName(String name) {
		return (IArtist)sessionFactory.getCurrentSession()
				.createCriteria(Artist.class)
				.add(Restrictions.eq("name", name))
				.uniqueResult();
	}

	/* (non-Javadoc)
	 * @see dao.IArtistDAO#getArtistsH()
	 */
	@SuppressWarnings("unchecked")
	public List<IArtist> getArtists() {
		return sessionFactory.getCurrentSession().createCriteria(Artist.class).addOrder(Order.asc("name")).list();
	}

	/* (non-Javadoc)
	 * @see dao.IArtistDAO#getArtistsByLetterH(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	public List<IArtist> getArtistsByLetter(String letter) {
		return sessionFactory.getCurrentSession()
			.createCriteria(Artist.class)
			.add(Restrictions.like("name", letter+"%"))
			.addOrder(Order.asc("name")).list();
	}
	
	@SuppressWarnings("unchecked")
	public List<IArtist> getArtistsByName(String name) {
		return sessionFactory.getCurrentSession()
			.createCriteria(Artist.class)
			.add(Restrictions.like("name", name))
			.addOrder(Order.asc("name")).list();
	}
	
	public IArtist getArtistbyId(Integer artistId) {
		return (IArtist)sessionFactory.getCurrentSession().load(Artist.class, artistId);
	}

	/* (non-Javadoc)
	 * @see dao.IArtistDAO#saveArtist(model.IArtist)
	 */
	public void saveArtist(IArtist artist) {
		sessionFactory.getCurrentSession().saveOrUpdate(artist);		
	}
}